package com.baosight.sczx.zm.cg.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cs.WorkSchedule;
import com.baosight.sczx.zm.cg.domain.ZMCGCallRecord;

/**
 * 电话综合记录管理
 * <p>Title: ServiceZMCG30.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-27 上午08:01:23  严洪浩  Create
 *</pre>
 */
public class ServiceZMCG30 extends ServiceEPBase {
	/**
	 * 初始进入方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCG30</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-25 上午14:37:20 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) 
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCG30</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-25 上午14:47:20 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		String fdMiningId = (String)UserSession.getInSessionProperty("miningCode");
		StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMiningId, true);
		//插入日期
		String fdCurrentDate = inInfo.getString("fdCurrentDate");
		if(fdCurrentDate==null || fdCurrentDate.trim().equals("")){
			fdCurrentDate = StaticTools.getDate();
			inInfo.set("fdCurrentDate", fdCurrentDate);
		}
		StaticTools.setQueryParameters(inInfo, "fdCurrentDate", fdCurrentDate, false);
		
		EiInfo outInfo = super.query(inInfo, "ZMCGCallRecord.query", new ZMCGCallRecord());
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.ch.status", new String[]{"草拟", "生效"}, new String[]{"草拟", "生效"}, true));//状态
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", true, UserSession.getInSessionProperty("miningCode").toString()));
		outInfo.addBlock(WorkSchedule.getWorkScheduleBlock("cmes.cp.workNum", fdMiningId, true));
		
		return outInfo;
	}

	/**
	 * 新增方法
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCBCoalseam</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-25上午11:34:17 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) 
	{
		EiInfo out=new EiInfo(); 
		ZMCGCallRecord _dom = new ZMCGCallRecord();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));

			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CG_CALLRECORD"));
			_dom.setFdMiningId(UserSession.getInSessionProperty("miningCode").toString());
			_dom.setFdMiningName(UserSession.getInSessionProperty("miningName").toString());// 矿井名称
			_dom.setFdCreateUserId(UserSession.getUserId().toString());
			_dom.setFdCreateUser(UserSession.getInSessionProperty("UserCname").toString());
			//如果有附件上传功能的模块，需要增加以下生成docid方法。生成规则调用统一的方法。修改时不用管docid，也就是docid一旦生成不能修改。除非删除
			_dom.setFdDocId(StaticTools.getDocId());
		    this.dao.insert("ZMCGCallRecord.insert", _dom);
			
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out; 		
				
	}

	/**
	 * 修改方法
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCBCoalseam</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-24上午13:34:17 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) 
	{
		EiInfo _temp = super.update(inInfo, "ZMCGCallRecord.update");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;	
	}
	
	/**
	 * 删除方法
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCBCoalseam</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-26上午13:34:17 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) 
	{
		EiInfo _temp = super.delete(inInfo, "ZMCGCallRecord.delete");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;	
	}
	
	/**
	 * 上报
	 * <p>Function: report</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-6下午04:07:27 张志芳
	 * </p>
	 *
	 */
	public EiInfo report(EiInfo inInfo)
	{
		EiInfo _temp = super.update(inInfo, "ZMCGCallRecord.report");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;		
	}
}
